<template>
    <div id="app">
        <router-view></router-view>
        <!--    <div>{{res}}</div>-->
    </div>
</template>

<script>
    export default {
        name: 'App',
        components: {},
        data() {
            return {
                res: {}
            }
        },
        methods: {
            getUser() {
                this.axios.get('/api/user').then((res={}) => {
                    //  保存到vuex里面
                  this.$store.dispatch('saveUserName',res.username);
                })
            },
            getCartCount() {
                console.log('app--getCartCount')
                this.axios.get('/api/carts/products/sum').then((res=0) => {
                    //  保存到vuex里面
                  this.$store.dispatch('saveCartCount',res);
                })
            }
        },
        mounted() {
            console.log('App mounted')
            // let that = this;

            /*本地加载*/
           /* this.axios.get('/mock/user/login.json').then((res) => {
                this.res = res
            })*/
            /*easy-mock平台实现加载*/

            //
            if(this.$cookie.get('userId')){
                this.getUser();
                this.getCartCount();
            }

        },

    }
</script>

<style lang="scss">

</style>
